
#ifndef Velyn_Displacement_h
#define Velyn_Displacement_h

#include "TMesh.h"

#include "IDisplacement.h"
#include "Spherical.h"
#include "Noise.h"
#include "Slice.h"

namespace Velyn {
    
    namespace Displacements {

        /*
         * Displacement uses a strategy design pattern for displacements.
         */
        
        class Displacement { 
            
        private:
            
            IDisplacement* displacement;
            
        public:
            
            /*
             * Types of displacements to specify for displacement.
             */
            
            enum DisplacementType {
                SPHERICAL, NOISE, SLICE
            };
            
            Displacement() {
                displacement = NULL;
            }
            
            Displacement(IDisplacement* d) : displacement(d) {}
            
            Displacement(DisplacementType displacementType, int numberSubdivisions) {
                
                switch(displacementType) {
                        
                    case SPHERICAL: {
                        displacement = new Spherical();
                    } break;
                        
                    case NOISE: {
                        displacement = new Noise(numberSubdivisions, 0.3f);
                    } break;
                        
                    case SLICE: {
                        displacement = new Slice();
                    } break;
                        
                    default: {} break;
                }
            }
            
            ~Displacement() {
                delete displacement;
            }
            
            void setDisplacement(IDisplacement* d) {
                
                if(displacement != NULL) {
                    delete displacement;
                }
                
                displacement = d;
            }
            
            int displace(TriangleMesh* mesh) {
                return displacement->displace(mesh);
            }
            
        };
        
    }
    
}

#endif
